package com.zhyonk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhyonk.config.propreties.BaiduProperties;
import com.zhyonk.domain.Banner;
import com.zhyonk.domain.Category;
import com.zhyonk.domain.ItemListInfo;
import com.zhyonk.mapper.BannerMapper;
import com.zhyonk.mapper.CategoryMapper;
import com.zhyonk.mapper.ItemListInfoMapper;
import com.zhyonk.service.AsyncService;
import com.zhyonk.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service("indexService")
public class IndexServiceImpl implements IndexService {

    @Autowired
    private BaiduProperties baiduProperties;

    @Autowired
    private AsyncService asyncService;

    @Autowired
    private BannerMapper bannerMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private ItemListInfoMapper itemListInfoMapper;


    @Override
    public HashMap<String, Object> getIndexBaseInfo() {
        //先查banner
        List<Banner> banners = bannerMapper.selectList(new QueryWrapper<Banner>().eq("status",1).orderByAsc("sort"));
        //查分类
        List<Category> categories = categoryMapper.selectList(new QueryWrapper<Category>().eq("status", 1).orderByAsc("sort"));
        //查topList
        List<ItemListInfo> itemList = itemListInfoMapper.selectList(new QueryWrapper<ItemListInfo>().eq("status", 1).orderByAsc("sort"));
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("banners",banners);
        resultMap.put("categories",categories);
        resultMap.put("itemList",itemList);
        return resultMap;
    }

    @Override
    public HashMap<String, Object> getTopItemList(int itemId) {
        HashMap<String, Object> resultMap = new HashMap<>();
        //查topList
        QueryWrapper<ItemListInfo> wrapper = new QueryWrapper<ItemListInfo>().eq("status", 1).orderByAsc("sort");
        if (itemId >0){
            wrapper.ne("query_id",itemId);
        }
        List<ItemListInfo> itemList = itemListInfoMapper.selectList(wrapper);
        resultMap.put("itemList",itemList);
        return resultMap;
    }

    @Override
    public HashMap<String, Object> getItemListByCategory(int categoryId) {
        HashMap<String, Object> resultMap = new HashMap<>();
        QueryWrapper<ItemListInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("category_id",categoryId);
        itemListInfoMapper.selectList(wrapper);
        List<ItemListInfo> itemList = itemListInfoMapper.selectList(wrapper);
        resultMap.put("itemList",itemList);
        return resultMap;
    }
}
